package com.mcy.springbatch.processer;

import com.mcy.springbatch.entity.SysUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.stereotype.Component;

/**
 * @author : Create By mcy
 * @date : 2019/8/25 22:58:33
 */
@Slf4j
@Component
public class SysUserRetryProcessor implements ItemProcessor<SysUser, SysUser> {

    int count = 0;

    @Override
    public SysUser process(SysUser item) throws Exception {
        log.info("正在处理：{}",item.toString());
        if(item.getId() == 15){
            count++;
            if (count > 5) {
                return item;
            }else {
                log.error("错误次数：{}",count);
                throw new RuntimeException("SysUserRetryProcessor抛出错误");
            }
        }
        return item;
    }
}
